package com.bolt.auth.security.auth.server.controller;

import com.bolt.auth.admin.api.feign.RemoteUserService;
import com.bolt.auth.security.auth.server.service.ValidateCodeService;
import com.bolt.auth.security.common.annotation.IgnoreFilter;
import com.bolt.auth.security.common.model.AuthUserDetails;
import com.bolt.auth.security.common.utils.SecurityUtils;
import com.bolt.convention.data.ResultMessage;
import com.bolt.convention.data.Results;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@Slf4j
public class IndexController {

    @Autowired
    private ValidateCodeService validateCodeService;

    @Autowired
    private RemoteUserService remoteUserService;


    @GetMapping("/login")
    private String login() {
        return "login";
    }


    @GetMapping(value = "/auth/captcha/graph")
    @IgnoreFilter
    @ResponseBody
    public ResultMessage<Map<String, Object>> captchaGraph() {
        return validateCodeService.createImageCode();
    }


    @GetMapping("/auth/userInfo")
    @ResponseBody
    public ResultMessage<AuthUserDetails> userInfo() {
        AuthUserDetails authUserDetails = SecurityUtils.getUser();
        return Results.success(authUserDetails);
    }

    @GetMapping("/auth/test")
    @IgnoreFilter
    @ResponseBody
    public ResultMessage<AuthUserDetails> test() {
        AuthUserDetails authUserDetails = SecurityUtils.getUser();
        return Results.success(authUserDetails);
    }

    @DeleteMapping("/auth/remove/token")
    @IgnoreFilter
    @ResponseBody
    public ResultMessage logout() {
        return Results.success();
    }


}

 